import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction


url = "http://127.0.0.1:4723/wd/hub"

param = 	{
	  "deviceName": "5EFGK18814000001",             # 设备序列号  -->  adb  devices
	  "platformName": "Android",                    # 安卓系统
	  "platformVersion": "10",                      # 鸿蒙要写 11版本，或者10版本
	  "appPackage": "com.chinamworld.main",         # adb  shell  pm list package  找到你的要测的包名称
	  "appActivity": "com.ccb.start.MainActivity",  #  aapt   d  badging  g:\sina.apk  -->lunachable-activity
	  "noReset": True,                              # 启动时不重置软件
	  "skipServerInstallation": True,               # 解决手机重复安装appium连接的软件
	  "automationName": "UiAutomator1"              # app权限自动获取
	}

driver = webdriver.Remote(url,param)
time.sleep(15)
# 广告弹窗点击关闭
try:
    el1 = driver.find_element(MobileBy.ACCESSIBILITY_ID,"关闭")
    el1.click()
    time.sleep(4)
except:
    time.sleep(4)

# 建行明细查询

# 点击账户查询
el1 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/androidx.slidingpanelayout.widget.SlidingPaneLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View/android.view.View[1]/android.view.View/android.view.View[2]/android.widget.Image")
el1.click()
time.sleep(25)
# 点击明细查询
el2 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[3]/android.view.View/android.view.View[4]")
el2.click()
time.sleep(10)
# 点击账户
el3 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[2]")
el3.click()
time.sleep(4)
# 选择第一个账户
el4 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[8]/android.view.View[3]/android.view.View[1]/android.view.View")
el4.click()
time.sleep(4)
# 点击子账户
el5 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[3]")
el5.click()
time.sleep(4)
# 点击第一个子账户
el6 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[8]/android.view.View[3]/android.view.View/android.view.View[1]")
el6.click()
time.sleep(4)
# 点击筛选
el7 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.view.View[4]")
el7.click()
time.sleep(4)
# 交易金额选择金额一千以下
el8 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[8]/android.view.View[3]/android.view.View[2]")
el8.click()
time.sleep(4)
# 收支类型选择支出
el9 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[7]/android.view.View/android.view.View/android.view.View[4]/android.view.View[5]")
el9.click()
time.sleep(4)
# 交易类型选择还款
el10 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[8]/android.view.View[3]/android.view.View[16]")
el10.click()
time.sleep(4)
# 向下滑动一次
TouchAction(driver)   .press(x=475, y=1784)   .move_to(x=484, y=1013)   .release()   .perform()
time.sleep(4)
# 交易方式选择支付宝
el11 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[8]/android.view.View[3]/android.view.View[23]")
el11.click()
time.sleep(4)
# 点击确定
TouchAction(driver).tap(x=780, y=1990).perform()
time.sleep(4)
# 选择查看第一条筛选结果
el12 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[7]/android.view.View/android.view.View/android.view.View[2]/android.view.View[6]/android.widget.Image")
el12.click()
time.sleep(10)
# 退出
driver.quit()